import {
  Body,
  Controller,
  Req,
  UseGuards,
  Request,
  Post,
  Get,
} from '@nestjs/common';
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
import { AuthGuard } from 'src/common/auth/auth.guard';
import { OrderService } from '../services/order.services';
import { OrderCreateDto } from '../dto/orderCreate.dto';
import { UserService } from '../services/user.service';
import { ResponseUtils } from 'src/common/utils/response.utils';

@ApiTags('订单模块')
@UseGuards(AuthGuard)
@ApiBearerAuth()
@Controller('api/order')
export class OrderController {
  constructor(
    private readonly orderService: OrderService,
    private readonly userService: UserService,
  ) {}

  @Get('list')
  async getOrderList(@Req() req) {
    const orderList = await this.orderService.getOrderList(req);
    return ResponseUtils.success(orderList);
  }

  @Post('create')
  async createOrder(
    @Body() orderCreateDto: OrderCreateDto,
    @Req() request: Request,
  ) {
    const orderNo = await this.orderService.createdOrder(
      orderCreateDto,
      request,
    );
    return ResponseUtils.success(orderNo);
  }
}
